package logic

import (
	"api/model/mysql"
	"context"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGoodsLogic {
	return &ListGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListGoodsLogic) ListGoods(in *house.ListGoodsRequest) (*house.ListGoodsResponse, error) {
	// todo: add your logic here and delete this line

	var goods []mysql.HouseGoods

	mysql.DB.Where("goods_price BETWEEN ? AND ?", 300, 500).Where("goods_status=?", 1).Order("created_at desc").Find(&goods)

	var list []*house.ListGoods

	for _, m := range goods {
		listGoods := house.ListGoods{
			GoodsImg:    m.GoodsImg,
			GoodsAuthor: m.GoodsAuthor,
			GoodsArea:   m.GoodsArea,
			GoodsPrice:  float32(m.GoodsPrice),
			GoodsStatus: int64(m.GoodsStatus),
			Id:          int64(m.ID),
		}
		list = append(list, &listGoods)
	}

	return &house.ListGoodsResponse{
		List: list,
	}, nil
}
